package com.cn.sys.main.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.cn.sys.frame.dao.BaseSpringJdbcDao;
import com.cn.sys.frame.service.impl.BaseServiceImpl;
import com.cn.sys.frame.util.page.PageData;
import com.cn.sys.frame.util.query.QueryCondition;
import com.cn.sys.main.annotation.OperationDescription;
import com.cn.sys.main.dao.SysOpeLogDao;
import com.cn.sys.main.entity.SysOpeLog;
import com.cn.sys.main.service.SysOpeLogService;

@Service("sysOpeLogService")
public class SysOpeLogServiceImpl extends BaseServiceImpl<SysOpeLog, Long> implements
		SysOpeLogService {
	private SysOpeLogDao sysOpeLogDao;
	
	@Autowired
	public void setBaseDao(BaseSpringJdbcDao<SysOpeLog, Long> sysOpeLogDao) {
		this.baseDao = sysOpeLogDao;
		this.sysOpeLogDao = (SysOpeLogDao) sysOpeLogDao;
	}

	@Cacheable(value="sysOpeLogCache", key=" #id + 'get'")
	public SysOpeLog get(Long id) throws Exception {
		return super.get(id);
	}
	
	@OperationDescription(operateType = "delete", content = "删除操作日志\nID:${#ids}", operateObj = "SysOpeLog")
	@CacheEvict(value="sysOpeLogCache", allEntries=true)
	public int delete(String ids) throws Exception {
		String sql = "DELETE FROM SYS_OPE_LOG WHERE ID IN ("+ids+")";
		int result = sysOpeLogDao.getJdbcTemplate().update(sql);
		return result;
	}

	public PageData<SysOpeLog> getPageData(PageData<SysOpeLog> pageData,
			QueryCondition queryCondition) throws Exception {
		String sql = "SELECT T1.ID,T1.TITLE,T2.NAME OPERATE_TYPE,T1.OPERATE_USER,T1.OPERATE_TIME,T3.NAME OPERATE_OBJ FROM SYS_OPE_LOG T1 " +
				"LEFT JOIN SYS_DICTIONARY T2 ON T1.OPERATE_TYPE=T2.VAL AND T2.PARENT_CODE='sys_log_operate_type' "
				+ "LEFT JOIN SYS_DICTIONARY T3 ON T1.OPERATE_OBJ=T3.VAL AND T3.PARENT_CODE='sys_log_operate_obj' WHERE 1=1 ";
		//String countSql = "SELECT COUNT(1) FROM (" + sql + ")";
		return sysOpeLogDao.getPageData(pageData, sql, queryCondition);
	}
	

}
